package redis

import "strconv"

func SyncGoodsStock(goodsId, stock int) {
	key := "goods_stock:goods_id_" + strconv.Itoa(goodsId)
	for i := 0; i < stock; i++ {
		Rdb.LPush(key, goodsId)
	}
}

// GetGoodsStock 获取虚拟库存
func GetGoodsStock(goodsId int) int64 {
	key := "goods_stock:goods_id_" + strconv.Itoa(goodsId)
	return Rdb.LLen(key).Val()
}

// Member
func AddGoods(userId int, goods map[string]interface{}) {
	key := "goods:user_id_" + strconv.Itoa(userId)
	Rdb.HMSet(key, goods)
}

// Member
func GetMemberInfo(userId int) (map[string]string, error) {
	key := "goods:user_id_" + strconv.Itoa(userId)
	result, err := Rdb.HGetAll(key).Result()
	if err != nil {
		return nil, err
	}
	return result, err
}
